Float field


In [1]:
from konfoo import Index, Byteorder, Float

Item

Item type of the field class.


In [2]:
Float.item_type


Out[2]:
ItemClass.Float = 30

Checks if the field class is a bit field.


In [3]:
Float.is_bit()


Out[3]:
False

Checks if the field class is a boolean field.


In [4]:
Float.is_bool()


Out[4]:
False

Checks if the field class is a decimal number field.


In [5]:
Float.is_decimal()


Out[5]:
False

Checks if the field class is a floating point number field.


In [6]:
Float.is_float()


Out[6]:
True

Checks if the field class is a pointer field.


In [7]:
Float.is_pointer()


Out[7]:
False

Checks if the field class is a stream field.


In [8]:
Float.is_stream()


Out[8]:
False

Checks if the field class is a string field.


In [9]:
Float.is_string()


Out[9]:
False

Field


In [10]:
real = Float(byte_order='auto')

In [11]:
real = Float()

Field view


In [12]:
real


Out[12]:
Float(index=Index(byte=0, bit=0, address=0, base_address=0, update=False), alignment=Alignment(byte_size=4, bit_offset=0), bit_size=32, value=0.0)

In [13]:
str(real)


Out[13]:
'Float32(Index(byte=0, bit=0, address=0, base_address=0, update=False), Alignment(byte_size=4, bit_offset=0), 32, 0.0)'

In [14]:
repr(real)


Out[14]:
'Float(index=Index(byte=0, bit=0, address=0, base_address=0, update=False), alignment=Alignment(byte_size=4, bit_offset=0), bit_size=32, value=0.0)'

Field name


In [15]:
real.name


Out[15]:
'Float32'

Field index


In [16]:
real.index


Out[16]:
Index(byte=0, bit=0, address=0, base_address=0, update=False)

Byte index of the field within the byte stream.


In [17]:
real.index.byte


Out[17]:
0

Bit offset relative to the byte index of the field within the byte stream.


In [18]:
real.index.bit


Out[18]:
0

Absolute address of the field within the data source.


In [19]:
real.index.address


Out[19]:
0

Base address of the byte stream within the data source.


In [20]:
real.index.base_address


Out[20]:
0

Indexes the field and returns the index after the field.


In [21]:
real.index_field(index=Index())


Out[21]:
Index(byte=4, bit=0, address=4, base_address=0, update=False)

Field alignment


In [22]:
real.alignment


Out[22]:
Alignment(byte_size=4, bit_offset=0)

Byte size of the field group which the field is aligned to.


In [23]:
real.alignment.byte_size


Out[23]:
4

Bit offset of the field within its aligned field group.


In [24]:
real.alignment.bit_offset


Out[24]:
0

Field size


In [25]:
real.bit_size


Out[25]:
32

Field byte order


In [26]:
real.byte_order


Out[26]:
Byteorder.auto = 'auto'

In [27]:
real.byte_order.value


Out[27]:
'auto'

In [28]:
real.byte_order.name


Out[28]:
'auto'

In [29]:
real.byte_order = 'auto'

In [30]:
real.byte_order = Byteorder.auto

Field value

Maximal float field value.


In [31]:
real.max()


Out[31]:
3.4028234663852886e+38

Minimal float field value.


In [32]:
real.min()


Out[32]:
-3.4028234663852886e+38

Smallest float field value.


In [33]:
real.smallest()


Out[33]:
1.1754943508222875e-38

Epsilon float field value.


In [34]:
real.epsilon()


Out[34]:
5.960464477539063e-08

Returns the float field value as a single precision floating point number.


In [35]:
real.value


Out[35]:
0.0

Returns the float field value aligned to its field group as a number of bytes.


In [36]:
bytes(real)


Out[36]:
b'\x00\x00\x00\x00'

In [37]:
bytes(real).hex()


Out[37]:
'00000000'

Returns the float field value as an integer number.


In [38]:
int(real)


Out[38]:
0

Returns the float field value as a single precision floating point number.


In [39]:
float(real)


Out[39]:
0.0

Returns the float field value as a boolean value.


In [40]:
bool(real)


Out[40]:
False

Field metadata

Returns the meatadata of the field as an ordered dictionary.


In [41]:
real.describe()


Out[41]:
OrderedDict([('address', 0),
             ('alignment', [4, 0]),
             ('class', 'Float32'),
             ('index', [0, 0]),
             ('max', 3.4028234663852886e+38),
             ('min', -3.4028234663852886e+38),
             ('name', 'Float32'),
             ('order', 'auto'),
             ('size', 32),
             ('type', 'Field'),
             ('value', 0.0)])

Deserialize


In [42]:
real.deserialize(bytes.fromhex('0000803f'), byte_order='little')


Out[42]:
Index(byte=4, bit=0, address=4, base_address=0, update=False)

In [43]:
real.value


Out[43]:
1.0

In [44]:
bytes(real)


Out[44]:
b'\x00\x00\x80?'

In [45]:
bytes(real).hex()


Out[45]:
'0000803f'

In [46]:
int(real)


Out[46]:
1

In [47]:
float(real)


Out[47]:
1.0

In [48]:
bool(real)


Out[48]:
True

Serialize


In [49]:
buffer = bytearray()

In [50]:
real.value = 1

In [51]:
real.value = 1.0

In [52]:
real.value = 0x1

In [53]:
real.value = 0b1

In [54]:
real.value = 0o1

In [55]:
real.value = True

In [56]:
real.value = 1.0

In [57]:
real.serialize(buffer, byte_order='little')


Out[57]:
Index(byte=4, bit=0, address=4, base_address=0, update=False)

In [58]:
buffer.hex()


Out[58]:
'0000803f'

In [59]:
bytes(real).hex()


Out[59]:
'0000803f'

In [ ]: